package com.seecoder.BlueWhale.controller;

import com.seecoder.BlueWhale.service.StoreService;
import com.seecoder.BlueWhale.util.SecurityUtil;
import com.seecoder.BlueWhale.vo.ResultVO;
import com.seecoder.BlueWhale.vo.StoreVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/api/stores")
@Slf4j
public class StoreController {
  @Autowired
  StoreService storeService;

  @Autowired
  SecurityUtil securityUtil;

  @PostMapping("/create")
  public ResultVO<StoreVO> create(@RequestBody StoreVO storevo) {
    log.info("User[{}] begins to create store", securityUtil.getUserId());
    ResultVO<StoreVO> ans = ResultVO.buildSuccess(storeService.create(storevo));
    log.info("User[{}] ends to created store", securityUtil.getUserId());
    return ans;
  }

  //获取所有商店信息
  @GetMapping("/info")
  public ResultVO<List<StoreVO>> info() {
    log.info("Begins to get all store info");
    ResultVO<List<StoreVO>> ans = ResultVO.buildSuccess(storeService.info());
    log.info("Ends to get all store info");
    return ans;
  }

  //获取某一商店信息
  @PostMapping("/info/single")
  public ResultVO<StoreVO> infoSingle(@RequestParam("id") int id) {
    log.info("Begins to get store info with id[{}]", id);
    ResultVO<StoreVO> ans = ResultVO.buildSuccess(storeService.infoSingle(id));
    log.info("Ends to get store info with id[{}]", id);
    return ans;
  }
}
